package com.supergdtop.www.run.tools;

import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.Signature;

import java.math.BigInteger;
import java.security.MessageDigest;

/**
 * 获取应用签名
 * Created by Asum on 2016/7/12 0012.
 */
public class AppPackageSigningTools {
    public static String get(Context context, String pkgname) {
        try {
            Signature[] signs = context.getPackageManager().getPackageInfo(pkgname, PackageManager.GET_SIGNATURES).signatures;
            if (signs.length > 0) {
                MessageDigest md5 = MessageDigest.getInstance("MD5");
                md5.update(signs[0].toByteArray());
                BigInteger bigInt = new BigInteger(1, md5.digest());
                return bigInt.toString(16);
            }
            return "";
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
}
